package com.ly.controller;

import com.ly.bean.EasybuyProductCategory;
import com.ly.bean.Result;
import com.ly.mapper.EasybuyProductCategoryMapper;
import com.ly.service.ProductCategoryService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
@author 李岩
@date 2021/12/14-13:52
@describe
*/
@RestController
@RequestMapping("/productCategory/")
public class ProductCategoryController{
    private final Logger logger= LoggerFactory.getLogger(ProductCategoryController.class);
    private ProductCategoryController(){
        System.out.println("ProductCategoryController   的controller层");
    }
    @Reference(url = "dubbo://localhost:20851")
    private ProductCategoryService productCategoryService;
    //根据父级id查询下级分类  （0，1，2，3）
    @GetMapping("findCategoryByPid/{pid}")
    public Result findCategoryByPid(@PathVariable("pid") Integer pid){
        List<EasybuyProductCategory> list = null;
        try {
            logger.info("根据父级id查询下级分类  "+pid);
            list = productCategoryService.findCategoryByPid(pid);
            return Result.getResult(true, 200, "查询成功", list);
        } catch (Exception e) {
            logger.error("根据父级id查询下级分类异常  "+e);
        }
        return Result.getResult(false, 404, "查询失败", null);
    }
}
